package io.github.loan.back.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import io.github.loan.common.controller.BaseController;
import io.github.loan.common.util.PageInfoUtil;
import io.github.loan.system.pojo.Cate;
import io.github.loan.system.pojo.Region;
import io.github.loan.system.service.ISystemService;
@Controller
@RequestMapping("/back/system/")
public class SystemBackController extends BaseController{
	@Resource
	private ISystemService systemService;
	
	/**
	 * 地区列表
	 */
	@RequestMapping("/regionList.mvc")
	public String regionList(HttpServletRequest request){
		/*接收参数*/
		String keyword=request.getParameter("keyword");
		String status=request.getParameter("status");
		String st=request.getParameter("st");
		String ed=request.getParameter("ed");
		
		String parentId=request.getParameter("parentId");
		if (st == null) {
			st = "";
		}
		if (ed == null) {
			ed = "";
		}
		if (parentId == null) {
			parentId = "";
		}

		Date stDate = null;
		Date edDate = null;
		if (!"".equalsIgnoreCase(st) && !"".equalsIgnoreCase(ed)) {
			stDate = this.dateFormatUtil.parseDateTime(st);
			edDate = this.dateFormatUtil.parseDateTime(ed);
		}
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("keyword", keyword);
		condMap.put("status", status);
		condMap.put("stDate", stDate);
		condMap.put("edDate", edDate);
		condMap.put("parentId", parentId);
		/* 查询数据,获取地区列表 */
		List<Region> regionList = this.systemService.findRegionCondListService(pageInfoUtil, condMap);
		/* 将结果放到request中 */
		request.setAttribute("regionList", regionList);
		request.setAttribute("pageInfoUtil", pageInfoUtil);
		
		request.setAttribute("keyword", keyword);
		request.setAttribute("status", status);
		request.setAttribute("st", st);
		request.setAttribute("ed", ed);
		request.setAttribute("parentId", parentId);
		return "/back/system/regionList";
	}
	/**
	 * 授权分类列表
	 */
	@RequestMapping("/cateList.mvc")
	public String cateList(HttpServletRequest request){
		/*接收参数*/
		String keyword = request.getParameter("keyword");
		String status = request.getParameter("status");
		String st = request.getParameter("st");
		String ed = request.getParameter("ed");
		
		String cateType=request.getParameter("cateType");
		if (st == null) {
			st = "";
		}
		if (ed == null) {
			ed = "";
		}
		if (cateType == null) {
			cateType = "";
		}

		Date stDate = null;
		Date edDate = null;
		if (!"".equalsIgnoreCase(st) && !"".equalsIgnoreCase(ed)) {
			stDate = this.dateFormatUtil.parseDateTime(st);
			edDate = this.dateFormatUtil.parseDateTime(ed);
		}

		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("keyword", keyword);
		condMap.put("status", status);
		condMap.put("stDate", stDate);
		condMap.put("edDate", edDate);
		condMap.put("cateType", cateType);
		/*查询数据*/
		List<Cate> cateList=this.systemService.findCateCondListService(pageInfoUtil, condMap);
		/*将结果放到request中*/
		request.setAttribute("cateList", cateList);
		request.setAttribute("pageInfoUtil", pageInfoUtil);
		
		request.setAttribute("keyword", keyword);
		request.setAttribute("status", status);
		request.setAttribute("st", st);
		request.setAttribute("ed", ed);
		
		request.setAttribute("cateType", cateType);
		return "/back/system/cateList" ; 
	}
}
